
namespace SB2.Core;
public class SugarRepository<T> : SimpleClient<T>, IScoped where T : class, new()
{
    public SugarRepository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
    {
        base.Context = context;//ioc注入的对象
                               // base.Context=DbScoped.SugarScope; SqlSugar.Ioc这样写
                               // base.Context=DbHelper.GetDbInstance()当然也可以手动去赋值

        // Init();
    }
    // 表不存在则创建
    public virtual void Init()
    {
        this.Context.CodeFirst.InitTables(typeof(T));
    }
    public long UserId => long.Parse(App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value ?? "0");
    /// <summary>
    /// 分页数据，单表查询
    /// </summary>
    /// <typeparam name="PagedResponse"> 分页数据 </typeparam>
    public virtual async Task<PagedResponse> GetPageListAsync<Q>(PagedRequest page) where Q : class, new()
    {
        return await Context.Queryable<T>().GetPageListAsync<T, Q>(page);
    }

}
